package com.qin.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qin.mall.service.OmsOrderReturnReasonService;
import com.qin.mall.domain.OmsOrderReturnReason;
import com.qin.mall.mapper.OmsOrderReturnReasonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 覃剑
* @description 针对表【oms_order_return_reason(退货原因表)】的数据库操作Service实现
* @createDate 2022-11-11 08:46:28
*/
@Service
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl<OmsOrderReturnReasonMapper, OmsOrderReturnReason>
    implements OmsOrderReturnReasonService {
    
    @Autowired
    private OmsOrderReturnReasonMapper orderReturnReasonMapper;
    

    /**
     * 添加订单原因
     */
    @Override
    public int create(OmsOrderReturnReason returnReason) {
        returnReason.setCreateTime(new Date());
        int result = orderReturnReasonMapper.insert(returnReason);
        return result;
    }

    /**
     * 修改退货原因
     */
    @Override
    public int update(Long id, OmsOrderReturnReason returnReason) {
        QueryWrapper<OmsOrderReturnReason> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        returnReason.setCreateTime(new Date());
        int update = orderReturnReasonMapper.update(returnReason, wrapper);
        return update;
    }

    /**
     * 批量删除退货原因
     */
    @Override
    public int delete(List<Long> ids) {
        QueryWrapper<OmsOrderReturnReason> wrapper = new QueryWrapper<>();
        wrapper.in("id",ids);
        int delete = orderReturnReasonMapper.delete(wrapper);
        return delete;
    }

    /**
     * 分页获取退货原因
     */
    @Override
    public Page<OmsOrderReturnReason> getlist(Integer pageNum,Integer pageSize) {
        Page<OmsOrderReturnReason> page = new Page<>(pageNum, pageSize);
        Page<OmsOrderReturnReason> pages = orderReturnReasonMapper.selectPage(page, null);
        List<OmsOrderReturnReason> list = pages.getRecords();
        return pages;
    }
    
    /**
     * 批量修改退货原因状态
     */
    @Override
    public int updateStatus(List<Long> ids, Integer status) {
        if(!status.equals(0)&&!status.equals(1)){
            return 0;
        }
        OmsOrderReturnReason reason = new OmsOrderReturnReason();
        reason.setStatus(status);
        QueryWrapper<OmsOrderReturnReason> wrapper = new QueryWrapper<>();
        wrapper.in("id",ids);
        int update = orderReturnReasonMapper.update(reason, wrapper);
        return update;
    }

    /**
     * 获取单个退货原因详情信息
     */
    @Override
    public OmsOrderReturnReason getItem(Long id) {
        OmsOrderReturnReason reason = orderReturnReasonMapper.selectById(id);
        return reason;
    }
}




